package com.donglink.test.storm.wordcount;

import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.StormSubmitter;
import org.apache.storm.generated.AlreadyAliveException;
import org.apache.storm.generated.AuthorizationException;
import org.apache.storm.generated.InvalidTopologyException;
import org.apache.storm.testing.TestWordSpout;
import org.apache.storm.topology.TopologyBuilder;

public class WordCountMain {
    public static void main(String[] args) throws InvalidTopologyException, AuthorizationException, AlreadyAliveException {
        //1.准备一个TopologyBuilder
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("words", new WordSpout(), 1);
        builder.setBolt("exclaim1", new SplitBolt(), 3)
                .shuffleGrouping("words");
        builder.setBolt("exclaim2", new CountBolt(), 2)
                .shuffleGrouping("exclaim1");

        //创建一个config用于创建toplogy
        Config config =new Config();
        config.setNumWorkers(3);


        //提交任务，两种模式本地模式，集群模式

        //集群
       // StormSubmitter.submitTopology("myFirst",config,builder.createTopology());


        //本地模式
        LocalCluster localCluster=new LocalCluster();

        localCluster.submitTopology("123",config,builder.createTopology());
    }
}
